<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<sfa:mainTitle></sfa:mainTitle>
		<%@ include file="../../../common/meta.jsp"%>
		<link rel="stylesheet" href="${path }/css/affixUpload.css"
			type="text/css"></link>
		<script type="text/javascript"
			src="${path}/script/lhgdialog/lhgdialog.min.js">
</script>
		<script type="text/javascript" src="${path}/script/affixUpload.js">
</script>

		<script type="text/javascript">
function opendialog() {
	var providerName = new Array();
	providerName = $("#provider").val().toString().split("|");
	$.dialog( {
		title : '产品关联',
		lock : true,
		background : '#FFF',
		opacity : 0.1,
		max : false,
		min : false,
		width : '650px',
		height : '550px',
		content : 'url:${path}/productandtrain/product/index/saleplanbook?productProvider='+providerName[1]
	});
}
function addProducts(productName,productId,productCode) {
	var list = $.dialog.list;
	for ( var i in list) {
		list[i].close();
	}
	document.getElementById("productName").value = productName;
	document.getElementById("productCode").value = productCode;
	document.getElementById("productId").value = productId;
	$("#productName").attr("readonly","true");
}
		
$(function() {
	//初始化控件 --1
	var actionPath = "${path}/affix/index/upload/SALEPROVIDERPLANBOOK";
	var div = 'sfaUpload'
	sfaUpload.init(actionPath, div);

	//设置表单验证
	var add = $("#add").validate( {
		rules : {
			trainType : {
				required : true
			},
			trainBranchid : {
				required : true
			},
			trainItem : {
				required : true,
				rangelength : [ 2, 20 ]
			},
			SALETRAINERID : {
				required : true
			},
			applyStartDate :{
				required : true
			},
			applyEedDate :{
				required : true
			},
			trainStratDate :{
				required : true
			},
			trainEndDate :{
				required : true
			},
		}
	});
	 
	$("#btn_submit")
			.click(function() {
				if (sfaUpload.getIsUploading()) {
					art.dialog( {
						content : "文件正在上传,请先取消上传文件！",
						lock : true,
						ok : true
					});
					return;
				}
				//debugger;
				var saleproviderplanbookid = '${saleproviderplanbookid}';
				var prospectusname = $("#prospectusname").val(); //计划书名称
				var branchid = $("#branchId").val(); //机构id
				var productname = $("#productname").val(); //产品名称
				var productId = $("#productId").val(); //产品名称
				var productCode = $("#productCode").val(); //产品名称
				var provider = $("#provider").val(); // 供应商
				var vildstartdate = $("#vildstartdate").val(); //有效时间始 
				var vildstopdate = $("#vildstopdate").val(); // 有效时间始止
				 
				var affixStr = "";
				$(".uoloadedFile").each(
						function(i, o) {
							var obj = $(o);
							affixStr += obj.attr("SALEAFFIXITEMID") + ";"
									+ obj.attr("isDel") + ";;";
						});

				//alert(affixStr);
				var data = {
					saleproviderplanbookid:saleproviderplanbookid,
					prospectusname:prospectusname,
					 branchid:branchid,
					 productId:productId,
					 productname:productname,
					 productCode:productCode,
					 provider:provider,
					
					 vildstartdate:vildstartdate,
					 vildstopdate:vildstopdate,
					 affixStr:affixStr
					 
				};
				$.ajax( {
					url : "${path}/productandtrain/prospectus/index/update",
					type : "POST",
					timeout : 10000,
					data : data,
					success : function(result) {
					 
							result = '(' + result + ')';
								var obj = eval(result);
								if (obj.result == true) {
									art.dialog( {
												icon : "succeed",
												content : obj.message,
												lock : true,
												ok : function() {
													window.location.href = "${path}/productandtrain/prospectus/index";
												}
											});
								} else {
									art.dialog( {
										icon : "error",
										content : obj.message,
										lock : true,
										ok : true
									});
								}
							}
						});
			});
});
 
</script>
	</head>
	<body id="master">
		<sfa:mainHeader></sfa:mainHeader>
		<div class="main">
			<div class="webpart3 contentarea">
				<div class="webpart-head">
					<div class="webpart-head-item">
					修改计划书
					</div>
				</div>
				<div class="webpart-main">
					<div class="webpart-main-item" style="padding: 30px;">
						<div class="d_formitem">
							<form id="add">
								<table cellspacing="0" cellpadding="0" class="formitem">
									<tr>
										<td width="15%">
											<span>建议书名称 </span>
										</td>
										<td>
											<input type="text" id="prospectusname" name="prospectusname"
												class="input-txt" maxlength="20" value="${prospectus.prospectusname}"/>

										</td>
									</tr>
									<tr>
										<td>
											<span>机构</span>
										</td>
										<td>
											<select class="input-txt" name="branchId" id="branchId">
												<c:forEach items="${BranchList}" var="branch">
													<option value="${branch.branchId }"
														<c:if test="${prospectus.branchid==branch.branchId}">selected='selected'</c:if>>
														${branch.branchName}
													</option>
												</c:forEach>
											</select>
										</td>
									</tr>
									<tr>
										<td>
											<span>供应商 </span>
										</td>
										<td>
											<select class="input-txt" name="provider" id="provider">
												<c:forEach items="${providerList}" var="provider">
													<option
														value="${provider.providerid}|${provider.providername}"
														<c:if test="${prospectus.providerid== provider.providerid }">selected='selected'</c:if>>
														${provider.providerabbr}
													</option>
												</c:forEach>
											</select>
										</td>
									</tr>
									<tr>
										<td>
											<span> 产品名称 </span>
										</td>
										<td>
											<input type="text" id="productname" name="productname"
												class="input-txt" maxlength="20" value="${prospectus.productname}" />
											<input type="hidden" id="productCode" name="productCode"
												class="input-txt" maxlength="20" value="${prospectus.productCode}"/>
											<input type="hidden" id="productId" name="productId"
												class="input-txt" maxlength="20" value="${productId}"/>
											<a href="#" onclick="opendialog()">添加产品</a>
										</td>
									</tr>
									<tr>
										<td>
											有效时间始
										</td>
										<td>
											<div id="markDiv">
												<input id="vildstartdate" name="vildstartdate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox" value="${prospectus.vildstartdate}" />
											</div>
										</td>
									</tr>
									</tr>
									<tr>
										<td>
											有效时间止
										</td>
										<td>

											<div id="markDiv">
												<input id="vildstopdate" name="vildstopdate"
													onfocus="WdatePicker({startDate:'%y-%M-01 00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})"
													readOnly="true" class="Wdate inputbox" value="${prospectus.vildstopdate}"/>
											</div>
										</td>
									</tr>


									<tr>
										<td>
											修改计划书
										</td>
										<td>
											<div class="">
												<div id="fileList">
				 
													<c:forEach items="${affixList}" var="affixItem">
													<div class="uoloadedFile" isDel="n"
														AFFIXPATH="${affixItem.SALEAFFIXITEMFILEPATH}"
														FILENAME="${affixItem.SALEAFFIXITEMFILENAME}"
														SALEAFFIXITEMID="${affixItem.SALEAFFIXITEMID}">
														<span>${affixItem.SALEAFFIXITEMFILENAME}</span>
														<a href="javascript:void(0)"
															onclick="sfaUpload.delUpload(this)">&nbsp;删除</a>

													</div>
												</c:forEach>
												 
												</div>
												<div id="sfaUpload"></div>
											</div>
 
											<input type="hidden" id="AFFIXPATH" name="AFFIXPATH" />
										</td>
									</tr>

									<tr>
										<th>
										</th>
										<td>
											<input type="button" id="btn_submit" tabindex="5"
												class="linkbtn2" value="保存">
											&nbsp;&nbsp;
											<input type="button" id="btn_back" tabindex="5"
												class="linkbtn2" value="返回"
												onclick="location.href='${path}/productandtrain/prospectus/index';">
										</td>
									</tr>
								</table>
							</form>
						</div>
					</div>
				</div>
				<div class="webpart-foot">
					<div class="webpart-foot-item">
					</div>
				</div>
			</div>
		</div>
		<sfa:mainFooter></sfa:mainFooter>
	</body>
</html>